import React from 'react';
class TimeForm extends React.Component{
    state={
        title: this.props.title || '',
        project: this.props.project || ''
    }
    handleTitleChange= (e)=>{
        this.setState({
            title: e.target.value
        })
    }
    handleProjectChange= (e)=>{
        this.setState({
            project: e.target.value
        })
    }
    handleFromSubmit = ()=>{
        this.props.onFormSubmit({
            id:this.props.id,
            title:this.state.title,
            project:this.state.project
        })
    }

    render() {
        console.log("TimeForm....",this.props)
        const submitText=this.props.id?'更新':'创建';
        return(
            <div>
                <div>
                    <label>名称</label>
                    <input type='text' value={this.state.title} onChange={this.handleTitleChange}/>
                </div>
                <div>
                    <label>项目</label>
                    <input type='text' value={this.state.project} onChange={this.handleProjectChange}/>
                </div>
                <div>
                    <button onClick={this.handleFromSubmit}>{submitText}</button>
                    <button onClick={this.props.onFromCancle}>删除</button>
                </div>
            </div>
        )
    }
}

export default TimeForm;